package set.学生成绩案例;

import java.util.Comparator;
import java.util.TreeSet;

/*案例需求
        用TreeSet集合存储多个学生信息(姓名，语文成绩，数学成绩)，
        并遍历该集合 要求：按照总分从高到低出现*/
public class Test {
    public static void main(String[] args) {
        //创建对象
        TreeSet<Student> ts=new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student s1, Student s2) {
                //主要条件
                int i1 = (s2.getChanise() + s2.getMath()) - (s1.getChanise() + s1.getMath());
                //次要条件
                int i2 = i1 == 0 ? s2.getChanise() - s1.getChanise() : i1;
                int i3 = i2 == 0 ? s2.getMath() - s1.getMath() : i2;
                int i4= i3 == 0 ? s2.getName().compareTo(s1.getName()) : i3;
                return i4;
            }
        });


        Student s1=new Student("孙悟空",95,98);
        Student s2=new Student("猪八戒",60,68);
        Student s3=new Student("沙和尚",85,78);
        Student s4=new Student("白龙马",85,69);
        Student s5=new Student("陈玄奘",85,69);
        //添加对象
        ts.add(s1);
        ts.add(s2);
        ts.add(s3);
        ts.add(s4);
        ts.add(s5);
        for (Student t : ts) {
            System.out.println(t);
        }
    }
}
